package com.crl.module.avatar.action
{
	import com.crl.module.avatar.core.IActor;
	
	import flash.utils.Dictionary;

	public class AbstractAction implements IAction 
	{
		protected var type:String;
		private var finished:Boolean;
		
		/**
		 * 此动作限制的后续动作; 
		 */		
		private var blocks:Dictionary;
		
		/**
		 * 此动作可替换的未处理动作列表中动作; 
		 */		
		private var replaces:Dictionary;
		
		
		public function AbstractAction()
		{
		}
		
		public function execute(actor:IActor):void{
			
		}
		
		public function getType() : String{
			return this.type;
		}
		
		public function giveup() : Boolean{
			return true;
		}
		
		public function onTick(actor:IActor) : void{
			
		}
		
		public function isBlock(action:IAction) : Boolean{
			return this.containersBlock(action.getType());
		}
		
		public function replace(action:IAction) : Boolean{
			var bool:Boolean=containersReplace(action.getType());
			
			if(bool){
				doReplace(action);
			}
			return bool;
		}
		
		/**
		 * 替换操作(一般只为当前的用户的动作做替换); 
		 * @param action
		 * 
		 */		
		protected function doReplace(action:IAction) : void{
			//todo override it;
		}
		
		public function get blockMessage() : String{
			return "";
		}
		
		
		/**
		 * 动作是否已完成; 
		 * @return 
		 * 
		 */		
		public function get isFinished():Boolean{
			return finished;
		}
		
		public function set isFinished(bool:Boolean):void{
			finished=bool;
		}
		
		
		/**
		 * 扩充限制列表; 
		 * @param args
		 * 
		 */		
		protected function addBlocks(...args):void{
			for each (var str:String in args){
				blocks[str]=1;
			}
		}
		
		protected function containersBlock(type:String):Boolean{
			if(blocks){
				return blocks[type]==1;
			}
			return false;
		}
		
		/**
		 * 扩充替换列表; 
		 * @param args
		 * 
		 */		
		protected function addReplaces(...args):void{
			for each (var str:String in args){
				replaces[str]=1;
			}
		}
		
		protected function containersReplace(type:String):Boolean{
			if(replaces){
				return replaces[type]==1;
			}
			return false;
		}
		
	}
}